#include "Hurricane.h"

const Vector2 Hurricane::AVAILABLES_DIRECTIONS[] = 
{ Vector2::Right(), Vector2::Left(), Vector2::Up(), Vector2::Down(), 
  Vector2::DownRight(), Vector2::DownLeft(), Vector2::UpLeft(), Vector2::UpRight() };


Vector2 Hurricane::RaffleDirection()
{
	int index = (int)(rand() % 8) - 1;
	
	return AVAILABLES_DIRECTIONS[index];
}

// return a column and a line
Vector2 Hurricane::RaffleBlock(int playerCol, int playerRow)
{
	Vector2 b = Hurricane::RaffleDirection();
	int newCol = Hurricane::distanceColumn + playerCol;
	int newRow = Hurricane::distanceLine + playerRow;

	if (newCol >= 6) newCol = 5;
	if (newRow >= 9) newRow = 8;
	if (newCol < 0) newCol = 0;
	if (newRow < 0) newRow = 0;

	if (b.X != 0) b.X *= newCol;
	if (b.Y != 0) b.Y *= newRow;

	return b;
}

void Hurricane::Update(Player player)
{
	if (!player.GetCollisionRect().Intersects(Hurricane::GetCollisionRect()) /*or collide with fireball*/) return;

	//Vector2 block = RaffleBlock(player.Column, player.Line);
	//player.GoToBlock(MyScene.blocks[block.X][block.Y]);
}

void Hurricane::Initialize(int level)
{
	switch(level)
	{
	case 1:
		condition = Hurricane::Smaller;
		break;
	case 2:
		condition = Hurricane::Greater;
		break;
	case 3:
		randomMotion = true;
		break;
	}
}

void Hurricane::Destroy()
{

}